home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
-
- #include <Folders.h>
- #include <Components.h>
-
- #include "IC Types.h"
- #include "IC API.h"
- #include "IC Keys.h"
- #include "IC Component API.h"
- #include "IC Component Selectors.h"
-
- #include "IC Component.h"
-
- // Registration flags
- enum
- {
- kRegisterLocally = 0,
- kRegisterGlobally
- };
-
- // globals used to register the component
- Handle gNameHdl;
- Handle gDescHdl;
- ComponentRoutineUPP gICComponentUPP;
- Component gICComponent;
-
- // routine to register the component
- OSErr InstallComponent(void);
-
- // sample routine to dump the names of the prefs resources
- void DumpPrefs(void);
- void DumpMaps(void);
-
- // an ICInstance global
- ICInstance inst;
-
- short gResFile;
-
- // main test routine
- int main(void);
- int main(void){
- ICError err;
- ICDirSpecArray folder_spec;
- Str255 email_address;
- long attr;
- long size;
- long seed;
- short vref;
- long dirid;
- OSErr oe;
-
- printf("Internet Config: C Example\n\n");
-
- printf("Registering the IC component...\n");
- oe=InstallComponent();
- printf("InstallComponent: %d\n",oe);
-
- // ICDisableComponent();
- // disabled; we really only want to test the component
- ICDisableLinkedCode();
-
- err = ICStart(&inst, 'CREA'); /* tell it your application creator */
- printf("ICStart: %ld\n", err);
-
- if (err!=0L)
- goto EndOfMain;
-
- Delay(60*2,&dirid);
-
- printf("ICUsingComponent: %s\n",ICUsingComponent(inst)?"true":"false");
-
- FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&vref,&dirid);
-
- folder_spec[0].vRefNum = vref; /* search for prefs in root of the system */
- folder_spec[0].dirID = dirid; /* volume, obviously you'd use other things */
- err = ICFindConfigFile(inst, 1, (ICDirSpecArrayPtr) &folder_spec);
- printf("ICFindConfigFile: %ld\n", err);
-
- err = ICBegin(inst, icReadWritePerm);
- printf("ICBegin: %ld %#lx\n", err,err);
- size = sizeof(email_address);
- err = ICGetPref(inst, "\pEmail", &attr, (Ptr) email_address, &size);
- printf("ICGetPref: %ld\n", err);
-
- p2cstr(email_address);
- printf("Your Email address is %s\n", email_address);
-
- Delay(60*2,&dirid);
-
- DumpPrefs();
-
- Delay(60*2,&dirid);
-
- DumpMaps();
-
- err = ICEnd(inst);
- printf("ICEnd: %ld\n", err);
-
- err = ICGetSeed(inst, &seed);
- printf("ICGetSeed: %ld = %ld\n", err, seed);
- /* now monitor this seed to see if any preferences have changed */
-
- err = ICStop(inst);
- printf("ICStop: %ld\n", err);
-
- fflush(stdout);
-
- EndOfMain:
-
- CloseResFile(gResFile);
-
- return 0;
- }
-
- void DumpPrefs(){
- ICError err;
- long count;
- long i;
- Str255 key;
-
- err = ICCountPref(inst, &count);
- printf("ICCountPref: %ld, count is %ld\n", err,count);
- for (i = 1; i <= count; i++) {
- err = ICGetIndPref(inst, i, key);
- p2cstr(key);
- printf(" ICGetIndPref: %ld - %s\n", err, &key);
- };
- }
-
- void DumpMaps(){
- ICError err;
- long count;
- Handle entries;
- long i,pos;
- ICMapEntry entry;
- ICAttr attr;
-
- union {
- OSType otype;
- char ostr[6];
- } mtype,mcreator,pcreator;
-
- // first need the mapping resource handle
- err=ICGetPrefHandle(inst,kICMapping,&attr,&entries);
- printf("ICGetPrefHandle: %ld\n",err);
- if (err!=noErr)
- return;
-
-
- err=ICCountMapEntries(inst,entries,&count);
- printf("ICCountMapEntries: %ld, count is %ld\n",err,count);
-
- if (err!=noErr)
- return;
-
- if (count>0){
-
- for (i=1;i<=count;i++){
- err=ICGetIndMapEntry(inst,entries,i,&pos,&entry);
-
- if (err!=noErr)
- printf("ICGetIndMapEntry: error %ld\n",err);
- else {
- mtype.otype=entry.file_type;
- mcreator.otype=entry.file_creator;
- pcreator.otype=entry.post_creator;
-
- mtype.ostr[4]=mcreator.ostr[4]=pcreator.ostr[4]=0;
-
- printf("ICGetIndMapEntry: type %s, creator %s, post creator %s, ext %#s\n",
- mtype.ostr,mcreator.ostr,pcreator.ostr,entry.extension);
- }
- }
- }
- }
-
- /*
- InstallComponent
-
- In order to test out the IC component, the code must be linked into the application,
- and it has to be registered by hand.
-
- This routine will take care of the whole thing...
-
- */
- OSErr InstallComponent(){
- OSErr err;
- Str255 cname="\pInternet Configuration";
- Str255 cdesc="\pProvides shared configuration of internet preferences";
- ComponentDescription desc;
- extern pascal void IC_Hello(void);
- FSSpec rs;
- short vref;
- long dirid;
-
- gNameHdl=NewHandle(256);
- HLock(gNameHdl);
- BlockMoveData(cname,*gNameHdl,cname[0]+1);
- HUnlock(gNameHdl);
-
- gDescHdl=NewHandle(256);
- HLock(gDescHdl);
- BlockMoveData(cdesc,*gDescHdl,cdesc[0]+1);
- HUnlock(gDescHdl);
-
- gICComponentUPP=NewComponentRoutineProc(InternetConfig);
-
- desc.componentType='PREF';
- desc.componentSubType='ICAp';
- desc.componentManufacturer='JPQE';
- desc.componentFlags=0L;
- desc.componentFlagsMask=0L;
-
- gICComponent=RegisterComponent(&desc,gICComponentUPP,kRegisterGlobally,gNameHdl,
- gDescHdl,(Handle)0);
-
- if (gICComponent==(Component)0)
- printf("Null component returned from RegisterComponent\n");
-
- FindFolder(kOnSystemDisk,kDesktopFolderType,kCreateFolder,&vref,&dirid);
- FSMakeFSSpec(vref,dirid,"\pinternet config.rsrc",&rs);
-
- gResFile=FSpOpenResFile(&rs,fsRdPerm);
- UseResFile(gResFile);
-
- return noErr;
- }
-
-
-
-
-